package com.pt.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 用户等级枚举
 */
@Getter
@AllArgsConstructor
public enum UserClass {
    NORMAL(1, "普通用户"),
    ADVANCED(2, "高级用户"),
    VIP(3, "VIP用户"),
    ADMIN(4, "管理员");

    private final int code;
    private final String desc;

    /**
     * 根据代码获取用户等级
     */
    public static UserClass getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        
        for (UserClass userClass : UserClass.values()) {
            if (userClass.getCode() == code) {
                return userClass;
            }
        }
        return null;
    }

    /**
     * 检查是否为管理员
     */
    public boolean isAdmin() {
        return this == ADMIN;
    }

    /**
     * 检查是否为VIP或以上等级
     */
    public boolean isVipOrAbove() {
        return this.code >= VIP.code;
    }

    /**
     * 检查是否为高级用户或以上等级
     */
    public boolean isAdvancedOrAbove() {
        return this.code >= ADVANCED.code;
    }
    
    /**
     * 获取最大同时下载数
     */
    public int getMaxSimDownloads() {
        switch (this) {
            case NORMAL:
                return 3;
            case ADVANCED:
                return 5;
            case VIP:
                return 10;
            case ADMIN:
                return 999;
            default:
                return 1;
        }
    }
    
    /**
     * 获取每日下载限制
     */
    public int getDailyDownloadLimit() {
        switch (this) {
            case NORMAL:
                return 5;
            case ADVANCED:
                return 50;
            case VIP:
                return -1;
            case ADMIN:
                return -1;
            default:
                return 5;
        }
    }
    
    /**
     * 获取下载速度限制（KB/s）
     */
    public long getDownloadSpeedLimit() {
        switch (this) {
            case NORMAL:
                return 1024; // 1MB/s
            case ADVANCED:
                return 2048; // 2MB/s
            case VIP:
                return 5120; // 5MB/s
            case ADMIN:
                return Long.MAX_VALUE; // 无限制
            default:
                return 512; // 512KB/s
        }
    }
    
    /**
     * 是否可以无需审核上传
     */
    public boolean isCanUploadWithoutReview() {
        return this.code >= ADVANCED.code;
    }
} 